export const IP = 'https://guizhouchenxun.com/api/'

// 封装uni.request
export default function request(url, method, options) {
	let header = {
		'content-type': 'application/json; charset=UTF-8',
		'Authorization': uni.getStorageSync('access_token') && uni.getStorageSync('token_type') +' ' + uni.getStorageSync('access_token'),
	}
	if (isType(options.data, 'Object')) {
		let NotFilter = !!options.data['_notFilter_'];
		delete options.data['_notFilter_'];
		Object.keys(options.data).forEach(key => {
			// 当参数为 '' 且没有规定不过滤的时候  如果不想要过滤 '' 可以在传参数的时候加入一个  notFilter true
			if (options.data[key] === '' && !NotFilter) {
				delete options.data[key];
			} else { // 过滤参数中的所有空格
				if (options.empty) {
					if (isType(options.data[key], 'String')) {
						options.data[key] = options.data[key].replace(/\s/g, '');
					}
				}
			}
		})
	}
	let urls = false
	if (url.indexOf("https") != -1) {
		urls = true
	}
	// console.log(JSON.stringify(options,null,2))
	return {
		header: header,
		url: urls ? url : IP + url,
		method: method,
		data: options
	}
}
export function isType(val, type) {
	return Object.prototype.toString.call(val).indexOf(type) >= 0
}
